package org.bugjail.servlet.language;

import java.util.Properties;

public class LanguageStringLoader {

	// LANGUAGES
	public static int LANG_ENG = 0;
	public static int LANG_POR = 1;
	public static int LANG_FRA = 2;
	
	// LANGUAGES FILES
	private static String PROPERTIES_ENG = "/org/bugjail/servlet/language/ENG.properties";
	private static String PROPERTIES_POR = "/org/bugjail/servlet/language/POR.properties";
	private static String PROPERTIES_FRA = "/org/bugjail/servlet/language/FRA.properties";

	
	// STRINGS
	public static String STR_HOME = "home";
	public static String STR_PROJECTS = "projects";
	public static String STR_TESTDESIGN = "testdesign";
	public static String STR_TESTEXECUTION = "testexecution";
	public static String STR_SEARCH = "search";
	public static String STR_SETTINGS = "settings";
	public static String STR_LOGOUT = "logout";
	public static String STR_LOGGED_IN_AS = "logged.in.as";
		
	public static String loadString(String str, int language) {
		try {
			Properties properties = new Properties();
			String file;
			if (language == LANG_POR) {
				file = PROPERTIES_POR;
			} else if (language == LANG_FRA) {
				file = PROPERTIES_FRA;
			} else {
				file = PROPERTIES_ENG;
			}
			properties.load(LanguageStringLoader.class.getResourceAsStream(file));
			return properties.getProperty(str);
		} catch (Exception e) {
			return null;
		}
	}
	
	public static String loadString(String str, int language, String defaultStr) {
		String result = loadString(str, language);
		if (result == null){
			result = defaultStr;
		}
		return result;
	}
	
	
}
